/*********************************************************************/
/*                                                                   */
/*      SVPWM Driver                                                 */
/*                                                                   */
/*      Last updated by:  CBS                                        */
/*      Last update date: 12/12/25                                   */
/*      Revision:         0                                          */
/*      Copyright:        DENSO                                      */
/*                                                                   */
/*********************************************************************/

#ifndef SVPWM_H_
#define SVPWM_H_

/*********************************************************************/
/*  version information                     SVPWM114                 */
/*********************************************************************/
#define MODULE_ID_SVPWM         99         /* To be added->Modules.h */
#define SVPWM_INSTANCE_ID       0

#define SVPWM_SW_MAJOR_VERSION  1
#define SVPWM_SW_MINOR_VERSION  0
#define SVPWM_SW_PATCH_VERSION  0

#define SVPWM_AR_MAJOR_VERSION  1
#define SVPWM_AR_MINOR_VERSION  0
#define SVPWM_AR_PATCH_VERSION  0

/*********************************************************************/
/*  include files                                                    */
/*********************************************************************/
#include "Std_Types.h"
#include "Ecuc_Types.h"
#include "Svpwm_Cfg.h"

/*********************************************************************/
/* SVPWM003: The detection of development errors is configu-         */
/*           rable (ON/OFF) at pre-compile time. The switch          */
/*           PwmDev Error Detect shall activate or deactiva-         */
/*           te the detection of all development errors.             */
/*                                                                   */
/* SVPWM064: If the PwmDevErorDetect switch is enabled, API          */
/*           parameter checking is enabled.                          */
/*                                                                   */
/* SVPWM078: Detected development errors shall be reported           */
/*           to the Det_ReportError service of the Developm-         */
/*           ent Error Tracer(DET) if the pre-processor              */
/*           PwmDevErorDetect is set.                                */
/*********************************************************************/

#if SVPWM_DEV_ERROR_DETECT == STD_ON
    #define Det_ReportError(m,i,a,e)            /* TO Be Implemented */
    #define Svpwm_ReportError(ErrorId) Det_ReportError\
                             ( MODULE_ID_SVPWM, 0, 0, ErrorId)
#else
    #define Svpwm_ReportError(ErrorId)                   /* SVPWM005 */
#endif /* SVPWM_DEV_ERROR_DETECT */

/*********************************************************************/
/*  Type Definitions                                                 */
/*********************************************************************/
/*********************************************************************/
/* SVPWM002: Development error values are of type uint8              */
/*********************************************************************/
typedef U2 Svpwm_ErrorType;

/*********************************************************************/
/* SVPWM058: The width of the duty cycle para is 16 bits             */
/*                                                                   */
/* SVPWM059: The SVPWM module shall comply with the                  */
/*           following scaling scheme for the duty cycle:            */
/*           0%    = 0x0000,                                         */
/*           100%  = 0x8000                                          */
/*********************************************************************/
typedef U4 Svpwm_DutyCycleType;                          /* SVPWM058 */

#define Svpwm_0_Percent    0x0000                        /* SVPWM059 */
#define Svpwm_100_Percent  0x8000

/*********************************************************************/
/* SVPWM108: Definition of type Svpwm_OutputStateType                */
/*********************************************************************/
typedef enum {
    SVPWM_LOW,
    SVPWM_HIGH
} Svpwm_OutputStateType;                                 /* SVPWM108 */

/*********************************************************************/
/* SVPWM109: Definition of type Svpwm_EdgeNotificationType           */
/*********************************************************************/
typedef enum {
    SVPWM_FALLING_EDGE =  SVPWM_LOW ,
    SVPWM_RISING_EDGE  =  SVPWM_HIGH,
    SVPWM_BOTH_EDGES
} Svpwm_EdgeNotificationType;

#define SVPWM_NO_EDGES (SVPWM_BOTH_EDGES + 1)

/*********************************************************************/
/* SVPWM110: Definition of type Svpwm_ChannelClassType               */
/*********************************************************************/
typedef enum {
    SVPWM_VARIABLE_PERIOD,
    SVPWM_FIXED_PERIOD,
    SVPWM_FIXED_PERIOD_SHIFTED
} Svpwm_ChannelClassType;

/*********************************************************************/
/* SVPWM179: Definition of type Svpwm_DutycyclesVectorType           */
/*********************************************************************/
typedef struct{
    U4    A_PHASE_DUTYCYCLE;
    U4    B_PHASE_DUTYCYCLE;
    U4    C_PHASE_DUTYCYCLE;
} Svpwm_DutycyclesVectorType;

extern const Svpwm_ConfigType SvpwmConfig;

extern std_VersionInfoType* versioninfo;


/*********************************************************************/
/* Enable/Disable Interrupt                                          */
/*********************************************************************/
#define Svpwm_EnableInterrupt(_ch)  (EMIOS.CH[_ch].CCR.B.FEN = 1)
#define Svpwm_DisableInterrupt(_ch) (EMIOS.CH[_ch].CCR.B.FEN = 0)

/*********************************************************************/
/* To Do: SVPWM_DUTYCYCLE_UPDATED_ENDPERIOD                          */
/*********************************************************************/

/*********************************************************************/
/* Constants Definitions                                             */
/*********************************************************************/

/*********************************************************************/
/* SVPWM002a: When API Svpwm_Init service is called with             */
/*            wrong parameter, development error                     */
/*           "SVPWM_E_PARAM_CONFIG(0x10)" shall be reported.         */
/*********************************************************************/
#define SVPWM_E_PARAM_CONFIG          0x10

/*********************************************************************/
/* SVPWM002b: When API service is used without module                */
/*            initialization, development error                      */
/*           "SVPWM_E_UNINIT(0x11) shall be reported.                */
/*********************************************************************/
#define SVPWM_E_UNINIT                0x11

/*********************************************************************/
/* SVPWM002c: When API service is used with an invalid               */
/*            channel identifier, development error "SVPWM_E         */
/*            _PARAM_CHANNEL(0x12)" shall be reported.               */
/*********************************************************************/
#define SVPWM_E_PARAM_CHANNEL         0x12

/*********************************************************************/
/* SVPWM002d: On usage of unauthorized SVPWM service on              */
/*            SVPWM channel configured a fixed period,               */
/*            development error"SVPWM_E_PERIOD_UNCHANGEABLE          */
/*            (0x13)" shall be reported.                             */
/*********************************************************************/
#define SVPWM_E_PERIOD_UNCHANGEABLE   0x13

/*********************************************************************/
/* SVPWM002e: When API Svpwm_Init service is called while            */
/*            the PWM driver has already been initialized,           */
/*            development error "SVPWM_E_ALREADY_INITIALIZED         */
/*            (0x14)" shall be reported.                             */
/*********************************************************************/
#define SVPWM_E_ALREADY_INITIALIZED   0x14

/*********************************************************************/
/* SVPWM151:  When API Svpwm_GetVersionInfo service is               */
/*            called with a NULL parameter, development              */
/*            error "SVPWM_E_PARAM_POINTER(0x15)" shall be           */
/*            reported.                                              */
/*********************************************************************/
#define SVPWM_E_PARAM_POINTER         0x15



/*********************************************************************/
/* Function Prototype Declarations                                   */
/*********************************************************************/
/*********************************************************************/
/* SVPWM095: Declaration of function Svpwm_Init                      */
/*********************************************************************/
void Svpwm_Init(const Svpwm_ConfigType* ConfigPtr);

/*********************************************************************/
/* SVPWM096: Declaration of function Svpwm_DeInit                    */
/*********************************************************************/
void Svpwm_DeInit();

/*********************************************************************/
/* SVPWM101: Declaration of Svpwm_DisableNotification                */
/* SVPWM102: Declaration of Svpwm_EnableNotification                 */
/*********************************************************************/
#if SVPWM_NOTIFICATION_SUPPORTED == STD_ON
void Svpwm_DisableNotification(Svpwm_ChannelType ChannelNumber); 

void Svpwm_EnsableNotification(Svpwm_EdgeNotificationType Notification,\
                               Svpwm_ChannelType ChannelNumber); 
#endif /* SVPWM_NOTIFICATION_SUPPORTED */

#if SVPWM_VERSION_INFO_API == STD_ON
/*********************************************************************/
/* SVPWM103: Declaration of function Svpwm_GetVersionInfo            */
/*********************************************************************/
void Svpwm_GetVersionInfo( std_VersionInfoType* versioninfo); 
#endif /* Svpwm_GetVersionInfo */

#if SVPWM_UPDATE_DUTYCYCLES_API == STD_ON
/*********************************************************************/
/* SVPWM200: Declaration of function Svpwm_UpdateDutyCycles          */
/*********************************************************************/
void Svpwm_UpdateDutyCycles( Svpwm_DutycyclesVectorType DutycyclesVector);
#endif /* SVPWM_UPDATE_DUTYCYCLES_API */

#endif
/**** End Of File ****************************************************/